package com.swz.dcrm.adpter;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.View;

import com.mobsandgeeks.saripaar.annotation.Or;
import com.swz.dcrm.R;
import com.swz.dcrm.base.ViewHolder;
import com.swz.dcrm.model.CarOrder;
import com.swz.dcrm.model.Clue;
import com.swz.dcrm.model.Order;

import java.util.List;

public class CarOrderAdapter extends CustomAdapter<Order> {

    private OnButtonClickListener onButtonClickListener;
    private Clue clue;
    private Drawable drawableRed;
    private Drawable drawableOrg;
    private Drawable drawableBlue;
    private Drawable drawableGreen;
    public interface OnButtonClickListener{
        void onCancelOrder(Order order);
        void onDelivery(Order order);
        void onItemClick(Order order);
    }

    public CarOrderAdapter(Context context,  List<Order> datas,Clue clue) {
        super(context, R.layout.item_order, datas);
        this.clue=clue;
        drawableBlue=context.getResources().getDrawable(R.drawable.shape_circle_blue);
        drawableOrg=context.getResources().getDrawable(R.drawable.shape_circle_orange);
        drawableRed=context.getResources().getDrawable(R.drawable.shape_circle_red);
        drawableGreen=context.getResources().getDrawable(R.drawable.shape_circle_green);
    }

    @Override
    protected void convert(ViewHolder holder, Order order, int position) {
        holder.setText(R.id.tv_name,clue.getCusName()+"");
        holder.setText(R.id.tv_order_date,mContext.getString(R.string.order_time,order.getOrderTime()));
        holder.setText(R.id.tv_delivery_date,mContext.getString(R.string.order_delevery_time,order.getPredictDeliveryCarTime()));
        holder.setText(R.id.tv_car_type,clue.getIntentCar());
        holder.setChecked(R.id.cb_buy_insurance,order.isInsuranceFinish());
        holder.setChecked(R.id.cb_boutique_install,order.isBoutiqueFinish());
        if(order.getWareHouseCarStatus()!=null&&order.getWareHouseCarStatus()==2){
            holder.setChecked(R.id.cb_car_warehousing,true);
        }else {
            holder.setChecked(R.id.cb_car_warehousing,false);
        }
        if(order.getStatus()==5||order.getStatus()==4){
            holder.getView(R.id.btn_cancel).setVisibility(View.GONE);
            holder.getView(R.id.btn_confirm).setVisibility(View.GONE);
        }else {
            holder.getView(R.id.btn_cancel).setVisibility(View.VISIBLE);
            holder.getView(R.id.btn_confirm).setVisibility(View.VISIBLE);
        }



        switch (clue.getLevel()){
            case 1:
                holder.getView(R.id.tv_level).setBackground(drawableRed);
                break;
            case 2:
                holder.getView(R.id.tv_level).setBackground(drawableOrg);
                break;
            case 3:
                holder.getView(R.id.tv_level).setBackground(drawableBlue);
                break;
            case 4:
                holder.getView(R.id.tv_level).setBackground(drawableGreen);
                break;
        }
        if(clue.getMortgage()!=null&&clue.getMortgage()){
            holder.getView(R.id.tv_loan).setVisibility(View.VISIBLE);
        }else {
            holder.getView(R.id.tv_loan).setVisibility(View.GONE);
        }
        if(clue.isBoy()){
            holder.setText(R.id.tv_sex,mContext.getString(R.string.item_boy));
        }else {
            holder.setText(R.id.tv_sex,mContext.getString(R.string.item_girl));
        }
        if(clue.getReplacementCar()!=null&&clue.getReplacementCar()){
            holder.getView(R.id.tv_substitution).setVisibility(View.VISIBLE);
        }else {
            holder.getView(R.id.tv_substitution).setVisibility(View.GONE);
        }
        if(clue.getLevelDesc()!=null){
            holder.setText(R.id.tv_level,clue.getLevelDesc().substring(0,1));
        }
        holder.setText(R.id.tv_order_num,order.getOrderNo()+"");
        holder.setOnClickListener(R.id.btn_cancel,v -> {
            if(onButtonClickListener!=null){
                onButtonClickListener.onCancelOrder(order);
            }
        });
        holder.setOnClickListener(R.id.btn_confirm,v -> {
            if(onButtonClickListener!=null){
                onButtonClickListener.onDelivery(order);
            }
        });
        holder.itemView.setOnClickListener(v -> {
            if(onButtonClickListener!=null){
                onButtonClickListener.onItemClick(order);
            }
        });
    }

    public OnButtonClickListener getOnButtonClickListener() {
        return onButtonClickListener;
    }

    public void setOnButtonClickListener(OnButtonClickListener onButtonClickListener) {
        this.onButtonClickListener = onButtonClickListener;
    }
}
